package com.qf.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 86199
 * @version V1.0
 * @Project jqueryDemo
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/5/25 13:57
 */
@WebServlet("/code")
public class CodeController extends BaseServlet {

    public void createCode(HttpServletRequest request, HttpServletResponse response)throws Exception{

        //1. 验证码工具类，参数，高度，验证码个数，这一行可以有多少个字符长度
        ValidateCode validateCode = new ValidateCode(100, 30, 4, 10);

        //2. 获取验证码字符串内容
        String code = validateCode.getCode();

        //3.将验证码字符串内容保存到tomcat的session会话对象中，供校验时候使用

        request.getSession().setAttribute("code",code);

        //4. 将验证码图片通过流写到页面展示

        validateCode.write(response.getOutputStream());

    }
}
